//https://leetcode.cn/problems/number-of-beautiful-pairs/?envType=daily-question&envId=2024-06-20
class Solution {
public:
    bool fun(int x,int y){
        int i = 2;
        while(i <=y){
            if(x%i == 0 && y %i == 0)
                return false;
            i++;
        }
        // cout<< x<<' '<<y<<endl;
        return true;
    }
    int countBeautifulPairs(vector<int>& nums) {
        int ret = 0;
        int size = nums.size();
        for(int i = 0; i<size;i++){
            for(int j = i+1;j<size;j++){
                int num1 = nums[i],num2 = nums[j]%10;
                while(num1 >= 10){
                    num1/=10;
                }
                if(num1 <num2){
                    swap(num1,num2);
                }
                if(fun(num1,num2)){
                   
                    ret++;
                }
            }
        }
        return ret;
    }
};